package com.yiqi.liebang.feature.mine.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.component.recyclerview.DividerItemDecoration;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.dialog.BottomBaseDialog;
import com.yiqi.liebang.common.widget.dialog.BounceBottomEnter;
import com.yiqi.liebang.common.widget.dialog.BounceTopEnter;
import com.yiqi.liebang.common.widget.dialog.FlipVerticalSwingEnter;
import com.yiqi.liebang.common.widget.dialog.SlideBottomExit;
import com.yiqi.liebang.entity.bo.QuestionBo;
import com.yiqi.liebang.entity.bo.UserCenterBo;
import com.yiqi.liebang.feature.home.view.TopicInfoActivity;
import com.yiqi.liebang.feature.order.view.OrderInfoActivity;

import java.util.ArrayList;
import java.util.List;

public class TopicListDialog extends BottomBaseDialog<TopicListDialog> {


    ImageView mBtnShareDialogCirclelose;
    RecyclerView mRvList;
    List<UserCenterBo.TopicBean> topicBeans;
    private Activity context;
    private boolean isLookMine;
    TopicDialogAdapter topicDialogAdapter;
    String userUid;
    public TopicListDialog(Activity context, View animateView) {
        super(context, animateView);
    }

    public TopicListDialog(Activity context, List<UserCenterBo.TopicBean> topicBeans, boolean isLookMine,String userUid) {
        super(context);
        this.topicBeans = topicBeans;
        this.context = context;
        this.isLookMine = isLookMine;
        this.userUid=userUid;
    }

    @Override
    public View onCreateView() {
        showAnim(new BounceBottomEnter());
        dismissAnim(new SlideBottomExit());
        View inflate = View.inflate(mContext, R.layout.dialog_topic_list, null);
        mBtnShareDialogCirclelose = inflate.findViewById(R.id.btn_topic_close);
        mRvList = inflate.findViewById(R.id.rv_dialog_topic);
        mRvList.setLayoutManager(new LinearLayoutManager(context));
        mRvList.addItemDecoration(new DividerItemDecoration(DividerItemDecoration.VERTICAL).setHeight(2));
        topicDialogAdapter = new TopicDialogAdapter();
        topicDialogAdapter.bindToRecyclerView(mRvList);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        mBtnShareDialogCirclelose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        List<UserCenterBo.TopicBean> beanList = new ArrayList<>();
        if (topicBeans != null && topicBeans.size() > 10) {
            beanList = topicBeans.subList(0, 10);
        } else {
            beanList = topicBeans;
        }

        topicDialogAdapter.setNewData(topicBeans);
        topicDialogAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(mContext, TopicInfoActivity.class);
                intent.putExtra("topic", topicDialogAdapter.getData().get(position).getId());
                intent.putExtra("user_id",userUid);
                mContext.startActivity(intent);
                dismiss();

            }
        });
    }

    public class TopicDialogAdapter extends BaseQuickAdapter<UserCenterBo.TopicBean, BaseViewHolder> {
        public TopicDialogAdapter() {
            super(R.layout.item_topic_dialog);
        }

        @Override
        protected void convert(BaseViewHolder helper, UserCenterBo.TopicBean item) {
            helper.setText(R.id.tv_topic_title, item.getTopicName()).setText(R.id.tv_topic_prize,
                    item.getTopicPrice() + "元/次");
        }
    }


}